﻿
Shader "Dan/UI/UI_LoadingHeart" {
    Properties {
        _ColorInside ("ColorInside", Color) = (1,0,0.5586209,1)
        _ColorOutside ("ColorOutside", Color) = (0.07843138,0.3921569,0.7843137,1)
        _Emission ("Emission", Float ) = 1
        _Level ("Level", Float ) = 5
        _Gap ("Gap", Range(0, 1)) = 0.25
        _GlowUp ("GlowUp", Range(0, 1)) = 0
        [MaterialToggle] _UsePingpong ("UsePingpong", Float ) = 0
        _PingpongSpeed ("PingpongSpeed", Float ) = 0.5
        [MaterialToggle] _UseTimeForPan ("UseTimeForPan", Float ) = 1
        _PanSpeed ("PanSpeed", Float ) = 0.5
        //[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
    }
    SubShader {
        Tags {
            "IgnoreProjector"="True"
            "Queue"="Transparent"
            "RenderType"="Transparent"
        }
        Pass {
           
            
            Blend SrcAlpha OneMinusSrcAlpha
            ZWrite Off
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"
            
            
            
             float4 _ColorOutside;
             float _Level;
             float _GlowUp;
             float _Gap;
             float _PanSpeed;
             float4 _ColorInside;
             float _Emission;
             fixed _UseTimeForPan;
             float _PingpongSpeed;
             fixed _UsePingpong;
             struct appdata {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };
            struct v2f {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            v2f vert (appdata v) {
                v2f o = (v2f)0;
                o.uv = v.uv;
                o.pos = UnityObjectToClipPos( v.vertex );
                return o;
            }
            
            float DrawHeart(float2 uv ,float2 offset,float2 size){
                float2 tempUV = (uv-offset)*size;
                float shapeU = tempUV.x;
                float shapeArc = tempUV.y-sqrt(atan(saturate(abs(shapeU)+0.125)));
                float heart = saturate(shapeU*shapeU+shapeArc*shapeArc);
                return heart;
            }

            float ShapeFlow01(float shape , float panSpeed, float usePan, 
  float pingpongSpeed, float usePingpong, float glowup, float level,float gap ){

  float panTime =(1 - shape)+(_Time.y*panSpeed);
  float useTimeForPan = lerp( shape, panTime, usePan );
  float shapeFlow = useTimeForPan * level;
  float gapLevel = step(gap,1 - frac(shapeFlow));

  float shinnTime =(frac(_Time.y*pingpongSpeed)-0.5)*2;
  shinnTime =saturate(abs(shinnTime)*1.25-0.125);
  float usePin = lerp( glowup, shinnTime , usePingpong );

  float useStyle = step((usePin*1.01),floor(shapeFlow) / (level - 1));
  
  return useStyle*gapLevel;
}



            fixed4 frag (v2f i ) : SV_Target {

                float2 uv =i.uv;


                float heart =DrawHeart (uv, float2(0.5,0.35),float2(2.1,2.7));
                
                float3 emissive = lerp(_ColorInside.rgb,_ColorOutside.rgb,heart)*_Emission;
                float3 finalColor = emissive;
                
                
                float flowStyle= ShapeFlow01(heart ,  _PanSpeed,  _UseTimeForPan,  _PingpongSpeed,  _UsePingpong,  _GlowUp,  _Level, _Gap );
                

                float heartMask = 1.0 - floor(heart);
               

                return fixed4(finalColor,flowStyle*heartMask);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"
    
}
